package io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 将"./src/main/java/io"目录下所有.java文件内容都输出到控制台
 * 思路
 * 1.使用一个File对象表示"./src/main/java/io"目录
 * 2.利用File
 */
public class Test03 {
    public static void main(String[] args) throws IOException {
        File dir = new File("./src/main/java/io");

        if (dir.isDirectory()){
            File [] subs = dir.listFiles();
            int i =0;
            for (File sub :subs){
                i++;
                String name = sub.getName();
                File file = new File("./src/main/java/io/"+name);
                FileInputStream fis = new FileInputStream(file);
                long len = file.length();
                byte [] date = new byte[(int)len];
                fis.read(date);
                String line = new String(date,StandardCharsets.UTF_8);
                System.out.println(line);
                System.out.println("第"+i+"次读取");
                fis.close();
            }
        }
    }
}
